package hdfs1;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
/**
 * hadoop jar eeeeeee.jar  hdfs1.Hdfs2LocalFile  /usr/kx/hdfs2Local_tmp.txt  /kxd/c.txt 
 * @author user
 *
 */
public class Hdfs2LocalFile {
	public static void main(String[] args) throws Exception {
		String local = args[0];
		String uri = args[1];
		FSDataInputStream in = null;
		OutputStream out = null;
		Configuration conf = new Configuration();
		try {

			FileSystem fs = FileSystem.get(URI.create(uri), conf);
			in = fs.open(new Path(uri));
			out = new FileOutputStream(local);
			byte[] buffer = new byte[30];
			in.skip(100);
			int bytesRead = in.read(buffer);
			if (bytesRead >= 0) {
				out.write(buffer, 0, bytesRead);

			}
		} finally {
			IOUtils.closeStream(in);
			IOUtils.closeStream(out);
		}
	}

}
